package com.cwl.pattern.迭代器模式;

import java.util.List;

/**
 * @program: pattern
 * @description: 具体的迭代器
 * @author: ChenWenLong
 * @create: 2019-07-10 11:20
 **/
public class ConcreteIterator implements Iterator {
    private List<Object> list=null;
    private int index=-1;

    public ConcreteIterator(List<Object> list) {
        this.list=list;
    }

    @Override
    public boolean hasNext() {
        if(index<list.size()-1) {
            return true;
        } else {
            return false;
        }
    }

    @Override
    public Object first() {
        index=0;
        Object obj=list.get(index);;
        return obj;
    }

    @Override
    public Object next() {
        Object obj=null;
        if(this.hasNext()) {
            obj=list.get(++index);
        }

        return obj;
    }
}
